<?php
namespace Common\Api;
class SendPhoneCodeApi  {
	private $user;
	private $pwd;
	private $phone;
	public function __construct($phone){
		$this->user = "jkwl565";
		$this->pwd  = "jkwl565565";//jkwl56595
		if(!$phone){
		   return '请输入手机号';
		}
		$this->phone = $phone; 
	}	
	function send($code_name,$content=''){
		$time = session('send_time');
		$now_time = time();
		if($now_time-$time<60){
			return '您当前发送过于频繁，请稍后发送';
		}
		$code=$this->getCode();//获取验证码
		//$content = $content.$code;
		if(empty($content)){
			$content="【Vwallet】您的验证码为".$code.",十分钟内有效,请勿告诉他人";//要发送的短信内容
		}
	//企业ID $userid
		$userid = '1111';
		//用户账号 $account
		$account = $this->user;
		//用户密码 $password
		$password = $this->pwd;
		//发送到的目标手机号码 $mobile
		$mobile = $this->phone;
		//短信内容 $content
		//发送短信（其他方法相同）
		$gateway = "http://sh2.cshxsp.com/sms.aspx?action=send&userid={$userid}&account={$account}&password={$password}&mobile={$mobile}&content={$content}&sendTime=";
		$result = file_get_contents($gateway);
		$xml = simplexml_load_string($result);
		if($xml->successCounts == 1){
		    session('code'.$code_name.$this->phone,$code);
			return 1;
		}else{
			return $xml->message;
		}
	}
	function sendMessage(){
	        $content="【CMSL理财】您好！您的入金预约已通过申请，本次申请15分钟内有效，请及时登录平台操作入金，感谢您的支持，祝您生活愉快！";//要发送的短信内容
	    //企业ID $userid
	    $userid = '1111';
	    //用户账号 $account
	    $account = $this->user;
	    //用户密码 $password
	    $password = $this->pwd;
	    //发送到的目标手机号码 $mobile
	    $mobile = $this->phone;
	    //短信内容 $content
	    //发送短信（其他方法相同）
	    $gateway = "http://sh2.cshxsp.com/sms.aspx?action=send&userid={$userid}&account={$account}&password={$password}&mobile={$mobile}&content={$content}&sendTime=";
	    $result = file_get_contents($gateway);
	    $xml = simplexml_load_string($result);
	    if($xml->successCounts == 1){
	        return 1;
	    }else{
	        return $xml->message;
	    }
	}
	private function getCode(){
		return rand(100000, 999999);
	}
	//判断时间是否超时
	public function checkTime($time,$time_limit=180){
		if ((time()-$time)<$time_limit&&!empty($time)){
			return '-1';
		}
	}
}